package com.zbkj.admin.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.stp.StpLogic;
import com.zbkj.common.constants.UploadConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SaTokenConfig implements WebMvcConfigurer {

    // 注册Sa-Token的注解拦截器，打开注解式鉴权功能
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 注册注解拦截器，并排除不需要注解鉴权的接口地址 (与登录拦截器无关)
        registry.addInterceptor(new SaInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/api/publicly/**",
                        "/api/admin/platform/getLoginPic",
                        "/api/admin/platform/login",
                        "/api/admin/platform/login/account/detection",
                        "/api/admin/merchant/getLoginPic",
                        "/api/admin/merchant/login",
                        "/api/admin/merchant/login/account/detection",
                        "/" + UploadConstants.UPLOAD_FILE_KEYWORD + "/**",
                        "/" + UploadConstants.DOWNLOAD_FILE_KEYWORD + "/**",
                        "/" + UploadConstants.UPLOAD_AFTER_FILE_KEYWORD + "/**",
                        "/*.html",
                        "/**/*.html",
                        "/**/*.css",
                        "/**/*.js",
                        "/profile/**",
                        "/common/download**",
                        "/common/download/resource**",
                        "/doc.html",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/v2/**",
                        "/swagger-ui.html/**",
                        "/*/api-docs",
                        "/druid/**",
                        "/captcha/get",
                        "/captcha/check",
                        "/api/admin/payment/callback/**",
                        "/api/admin/merchant/finance/**",
                        "/api/public/**",
                        "/error")
        ;
    }

    // Sa-Token 整合 jwt (Simple 简单模式)
//    @Bean
//    public StpLogic getStpLogicJwt() {
//        return new StpLogicJwtForSimple();
//    }
}
